package com.futures.investm.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.futures.investm.R;
import com.futures.investm.entity.Future;

import java.util.ArrayList;


/**
 * 国内期货adapter
 */
public class CnFutureAdapter extends BaseQuickAdapter<Future, BaseViewHolder> {

    public CnFutureAdapter() {
        super(R.layout.item_cn_future, new ArrayList<Future>());
    }

    @Override
    protected void convert(BaseViewHolder holder, final Future item) {


        //结算价
        double oldPercent = Double.parseDouble(item.data.get(10));
        //最新价
        double newPercent = Double.parseDouble(item.data.get(8));
        //差价
        double price_prse = newPercent - oldPercent;


        double percentPrice = price_prse / Double.parseDouble(item.data.get(10)) * 100;

        holder.setText(R.id.tv_name, item.name);
        holder.setText(R.id.tv_new_price, String.format("%.2f", newPercent));
        holder.setText(R.id.tv_percent, String.format("%.2f", percentPrice) + "%");


        if (price_prse > 0) {
            holder.setTextColor(R.id.tv_new_price, mContext.getResources().getColor(R.color.market_red));
            holder.setTextColor(R.id.tv_percent, mContext.getResources().getColor(R.color.market_red));
        } else {
            holder.setTextColor(R.id.tv_new_price, mContext.getResources().getColor(R.color.market_blue));
            holder.setTextColor(R.id.tv_percent, mContext.getResources().getColor(R.color.market_blue));
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                IntentUtils.goMarketDetailsActivity(mContext,item.code,item.name,"0","");
            }
        });
    }


}
